﻿using System.Net;
using System.Web;
using System.Web.Mvc;
using ResourcesOverMvc.Web.Mvc;
using Samples.WebService.Models;

namespace Samples.WebService.Controllers
{
    public class ErrorController : Controller
    {
        public ActionResult ErrorDetail(HttpException httpException)
        {
            var detail = new ErrorDetail(httpException.Message);

            if (HttpContext.IsDebuggingEnabled && (httpException.InnerException != null))
            {
                detail.DebugInformation = httpException.InnerException.Message;
            }

            // Errors should never be cached as clients need to be able to try again
            HttpContext.Response.Cache.SetCacheability(HttpCacheability.NoCache);

            return this.View("ErrorDetail", detail, new HttpStatusCode?((HttpStatusCode)httpException.GetHttpCode()));
        }

        public ActionResult Http404(string url)
        {
            return this.View("ErrorDetail", new ErrorDetail {Description = "The requested URI is not valid."}, HttpStatusCode.NotFound);
        }
    }
}
